package com.android.ailaoshan.tools;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 检查网络连接状况
 */
public class CheckInternet {

    public boolean isInternetAvailable(Context mContext){
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

        if(connectivityManager == null){
            return false;
        }else{
            NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();

            if(networkInfos != null){
                for(NetworkInfo networkInfo:networkInfos){
                    if(networkInfo.getState() == NetworkInfo.State.CONNECTED){
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
